﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Rison.DataAccess.Data.ZJCP;
using System.Text;

namespace Rison.Web.ZJCP.ashx
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class load_illustrativecase_list : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string departmentId = context.Request.Params["departmentId"];
            if (String.IsNullOrEmpty(departmentId))
            {
                context.Response.Write("false");
            }
            else
            {
                context.Response.Write(String.Format("[{0}]", loadIllustrativecaseList(departmentId)));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private string loadIllustrativecaseList(string departmentId)
        {
            string sql = String.Format("select il_id, il_case_reason from Illustrativecase where department_id='{0}'", departmentId);
            DataSet ds = DbAccess.executeQuery(sql);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (i > 0)
                {
                    sb.Append(",");
                }
                sb.Append(String.Format("{{ilId:\"{0}\",caseReason:\"{1}\"}}", replaceSpicalCharacter(ds.Tables[0].Rows[i][0].ToString()), replaceSpicalCharacter(ds.Tables[0].Rows[i][1].ToString())));
            }
            return sb.ToString();
        }
        private string replaceSpicalCharacter(string str)
        {
            if (!String.IsNullOrEmpty(str))
            {
                str = str.Replace("\n", "\\n");
                str = str.Replace("\r", "\\r");
                str = str.Replace("\"", "\\\"");
            }
            return str;
        }
    }
}
